package Plants;

import SmartGrid.ExecutionEngine;
import Tasks.IncrementElectricOutputAndSend;

public class PowerLine {
	
	PowerPlant plant1;
	PowerPlant plant2;
	
	PowerPlant sending;
	PowerPlant receiving;
	
	int electricCurrent;
	int maxCapacity;
	float distance;
	
	public PowerLine(PowerPlant plant1, PowerPlant plant2)
	{
		this.plant1 = plant1;
		this.plant2 = plant2;
		sending = null;
		receiving = null;
		electricCurrent = 0;
		maxCapacity = 100;
		distance = 1;
	}
	
	/**
	 * Retrieve the power plant on the other side of this power line from source
	 * @param source
	 * @return
	 */
	public PowerPlant getEndNode(PowerPlant source)
	{
		if(source == plant1)
			return plant2;
		if(source == plant2)
			return plant1;
		return null;
	}
	
	public int getCurrent()
	{
		return electricCurrent;
	}
	
	public float getDistance()
	{
		return distance;
	}
	
	public void setDistance(float distance)
	{
		this.distance = distance;
	}
	
	/**
	 * Creates a task for the execution engine to increment the sources electric output and send the energy to the destination
	 * @param source
	 * @param destination
	 * @param amount
	 */
	public void sendEnergy(PowerPlant source, PowerPlant destination, int amount)
	{
		this.sending = source;
		this.receiving = destination;
		
		electricCurrent = amount;
		
		IncrementElectricOutputAndSend task = new IncrementElectricOutputAndSend(source, destination, source.getElectricOutput() + amount, amount);
		ExecutionEngine.addRecurringTask(task, Tools.Options.INCREMENT_SEND_ENERGY_DELAY);
	}

}
